package com.ziyun.erp.web.modules.quotePaperKai.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.erp.common.utils.UserUtils;
import io.renren.common.validator.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.quotePaperKai.entity.QuotePaperKaiEntity;
import com.ziyun.erp.modules.quotePaperKai.service.QuotePaperKaiService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 纸张开度表
 *
 * @author xueqz
 * @email 
 * @date 2018-09-05 16:30:23
 */
@RestController
@RequestMapping("quotePaperKai/quotepaperkai")
public class QuotePaperKaiController {
    @Autowired
    private QuotePaperKaiService quotePaperKaiService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quotePaperKai:quotepaperkai:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = quotePaperKaiService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("quotePaperKai:quotepaperkai:info")
    public R info(@PathVariable("id") Integer id){
        QuotePaperKaiEntity quotePaperKai = quotePaperKaiService.selectById(id);

        return R.ok().put("quotePaperKai", quotePaperKai);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("quotePaperKai:quotepaperkai:save")
    public R save(@RequestBody QuotePaperKaiEntity quotePaperKai){
        quotePaperKai.setCreateUser(UserUtils.getCurentUser().getUsername());
        quotePaperKaiService.insert(quotePaperKai);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("quotePaperKai:quotepaperkai:update")
    public R update(@RequestBody QuotePaperKaiEntity quotePaperKai){
        ValidatorUtils.validateEntity(quotePaperKai);
        quotePaperKaiService.updateAllColumnById(quotePaperKai);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("quotePaperKai:quotepaperkai:delete")
    public R delete(@RequestBody Integer[] ids){
//        quotePaperKaiService.deleteBatchIds(Arrays.asList(ids));
        quotePaperKaiService.flagDel(StringUtils.join(ids,","));

        return R.ok();
    }

}
